//
//  PickBallNewController.m
//  inrtest
//
//  Created by 宋辉 on 2017/5/5.
//  Copyright © 2017年. All rights reserved.
//

#import "PickBallNewController.h"
#import "CollectionViewCell.h"
#import "MyHeaderView.h"
#import <AVFoundation/AVFoundation.h>
#import "BuyLotteryViewController.h"
@interface PickBallNewController ()<UICollectionViewDataSource,UICollectionViewDelegate>
{
    NSString *Newtitle;
    NSInteger Count_row;
    NSInteger Count_Random;
    NSInteger Count_section;
    NSString *Methods_Name;
    NSArray *section_array;
    NSString *parameters;
    NSString* lotteryType;
    
    
    int index;
    
    NSMutableArray* dataArray;
}

@property(nonatomic,strong)UICollectionView *CollectionView;
@property(nonatomic,strong)NSMutableArray *Source_Array;

@property(nonatomic,strong)NSMutableArray *Other_Array;

@property(nonatomic,strong)NSMutableDictionary *Source_Dict;

@property(nonatomic,strong)NSMutableArray *Key_Array;


@end

@implementation PickBallNewController

-(void)ContrillerName:(NSString *)contrname
          MethodsName:(NSString *)methodsname
         SectionCount:(NSInteger)sectioncount
             RowCount:(NSInteger)rowcount
          RandomCount:(NSInteger)randomcount OtheParameter:(NSString *)parameter
     SectionNameArray:(NSArray *)array{
    
    Newtitle = contrname;
    self.title = Newtitle;
    Count_row = rowcount;
    Count_Random = randomcount;
    Count_section = sectioncount;
    Methods_Name = methodsname;
    parameters = parameter;
    section_array = array;
    //    lotteryType=parameter;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    dataArray=[NSMutableArray array];
    [self initNav];
    [self CreateTopView];
    [self CreateSource];
    [self CreateBView];
}
-(void)initNav{
    
    [self.navigationItem setTitle:Newtitle];
    [self.view setBackgroundColor:[UIColor whiteColor]];
    
    // 设置允许摇一摇功能
    [UIApplication sharedApplication].applicationSupportsShakeToEdit = YES;
    // 并让自己成为第一响应者
    [self becomeFirstResponder];
    
}
-(void)CreateTopView{
    
    //    标题
    UILabel * textlabel = [UILabel new] ;
    //    textlabel.text = @"玩法: 三星直选";
    textlabel.text = [NSString stringWithFormat:@"玩法:%@",Methods_Name];
    textlabel .textColor = [UIColor grayColor];
    textlabel.textAlignment=NSTextAlignmentCenter;
    textlabel .font = [UIFont systemFontOfSize:15];
    [self.view addSubview:textlabel];
    [textlabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(ScreenWidth);
        make.height.mas_equalTo(15);
        make.top.equalTo(self.view).with.offset(5);
        make.leading.equalTo(self.view).with.offset(0);
    }];
    
    
    UIView *line = [[UIView alloc]init];
    line.backgroundColor = Color(200, 199, 204, 1);
    [self.view addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(ScreenWidth);
        make.height.mas_equalTo(1);
        make.top.equalTo(textlabel.mas_bottom).with.offset(5);
        make.leading.equalTo(self.view).with.offset(0);
    }];
    
    // 球号
    UICollectionViewFlowLayout *layOut = [[UICollectionViewFlowLayout alloc]init];
    
    if(iPhoneX){
        
        self.CollectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0,25+1 , ScreenWidth, ScreenHeigth-88-25-52-1-34) collectionViewLayout:layOut];
    }else{
        
        self.CollectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0,25+1 , ScreenWidth, ScreenHeigth-64-25-52-1) collectionViewLayout:layOut];
        
    }
    _CollectionView.allowsMultipleSelection = YES;
    self.CollectionView.backgroundColor = [UIColor whiteColor];
    //    self.CollectionView.scrollEnabled = NO;
    [self.CollectionView registerClass:[CollectionViewCell class] forCellWithReuseIdentifier:@"coll_cell"];
    
    [self.CollectionView registerClass:[MyHeaderView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeaderView"];
    
    self.CollectionView.delegate = self;
    self.CollectionView.dataSource = self;
    [self.view addSubview:self.CollectionView];
    
    
}
/**
 下方按钮
 */
-(void)CreateBView{
    
    UIView *line2 = [[UIView alloc]init];
    line2.backgroundColor = DEF_COLOR_F0F0F0;
    [self.view addSubview:line2];
    
    if(iPhoneX){
        
        [line2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@0);
            make.bottom.mas_equalTo(self.view.mas_bottom).offset(-52-34);
            make.size.mas_equalTo(CGSizeMake(SCREEN_SIZE.width, 1));
        }];
        
    }else{
        
        [line2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@0);
            make.bottom.mas_equalTo(self.view.mas_bottom).offset(-52);
            make.size.mas_equalTo(CGSizeMake(SCREEN_SIZE.width, 1));
        }];
        
    }
    
    UIImageView* clearImage=[UIImageView new];
    clearImage.image=[UIImage imageNamed:@"LJT_"];
    [self.view addSubview:clearImage];
    
    if(iPhoneX){
        
        [clearImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(20);
            make.height.mas_equalTo(22);
            make.bottom.equalTo(self.view.mas_bottom).with.offset(-25-34);
            make.leading.equalTo(self.view).with.offset(12);
        }];
        
    }else{
        
        [clearImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(20);
            make.height.mas_equalTo(22);
            make.bottom.equalTo(self.view.mas_bottom).with.offset(-25);
            make.leading.equalTo(self.view).with.offset(12);
        }];
        
    }
    
    UILabel* faxed=[UILabel new];
    faxed.text=@"清空";
    faxed.font=[UIFont systemFontOfSize:12];
    faxed.textColor=baseLightBlackColor;
    faxed.textAlignment=NSTextAlignmentCenter;
    [self.view addSubview:faxed];
    [faxed mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.width.mas_equalTo(25);
        make.height.mas_equalTo(12);
        make.top.equalTo(clearImage.mas_bottom).with.offset(5+3);
        make.leading.equalTo(self.view).with.offset(10);
    }];
    
    UIButton* clearBut=[UIButton new];
    [clearBut addTarget:self action:@selector(clearButClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:clearBut];
    
    if(iPhoneX){
        
        [clearBut mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(50);
            make.height.mas_equalTo(51);
            make.bottom.equalTo(self.view.mas_bottom).with.offset(0-34);
            make.leading.equalTo(self.view).with.offset(0);
        }];
        
    }else{
        
        [clearBut mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(50);
            make.height.mas_equalTo(51);
            make.bottom.equalTo(self.view.mas_bottom).with.offset(0);
            make.leading.equalTo(self.view).with.offset(0);
        }];
        
    }
    
    UIView* line3=[UIView new];
    line3.backgroundColor=DEF_COLOR_F0F0F0;
    [self.view addSubview:line3];
    
    if(iPhoneX){
        
        [line3 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(1);
            make.height.mas_equalTo(42);
            make.bottom.equalTo(self.view.mas_bottom).with.offset(-5-34);
            make.leading.equalTo(clearImage.mas_trailing).with.offset(15);
        }];
        
    }else{
        
        [line3 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(1);
            make.height.mas_equalTo(42);
            make.bottom.equalTo(self.view.mas_bottom).with.offset(-5);
            make.leading.equalTo(clearImage.mas_trailing).with.offset(15);
        }];
        
    }
    
    UIImageView* shackImage=[UIImageView new];
    shackImage.image=[UIImage imageNamed:@"YYY_"];
    [self.view addSubview:shackImage];
    if(iPhoneX){
        
        [shackImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(25);
            make.height.mas_equalTo(25);
            make.bottom.equalTo(self.view.mas_bottom).with.offset(-22-34);
            make.leading.equalTo(line3.mas_trailing).with.offset(15);
        }];
        
    }else{
        
        [shackImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(25);
            make.height.mas_equalTo(25);
            make.bottom.equalTo(self.view.mas_bottom).with.offset(-22);
            make.leading.equalTo(line3.mas_trailing).with.offset(15);
        }];
        
    }
    
    UILabel* faxed2=[UILabel new];
    faxed2.text=@"摇号";
    faxed2.font=[UIFont systemFontOfSize:12];
    faxed2.textColor=baseLightBlackColor;
    faxed2.textAlignment=NSTextAlignmentCenter;
    [self.view addSubview:faxed2];
    [faxed2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(25);
        make.height.mas_equalTo(12);
        make.top.equalTo(shackImage.mas_bottom).with.offset(5);
        make.leading.equalTo(line3.mas_trailing).with.offset(11);
    }];
    
    UIButton* shackBut=[UIButton new];
    [shackBut addTarget:self action:@selector(shackButClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:shackBut];
    
    
    if(iPhoneX){
        
        [shackBut mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(50);
            make.height.mas_equalTo(51);
            make.bottom.equalTo(self.view.mas_bottom).with.offset(0-34);
            make.leading.equalTo(line3.mas_trailing).with.offset(0);
        }];
        
    }else{
        
        [shackBut mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(50);
            make.height.mas_equalTo(51);
            make.bottom.equalTo(self.view.mas_bottom).with.offset(0);
            make.leading.equalTo(line3.mas_trailing).with.offset(0);
        }];
        
    }
    
    UILabel* faxed3=[UILabel new];
    faxed3.text=@"摇一摇，机选一注";
    faxed3.font=[UIFont systemFontOfSize:14];
    faxed3.textColor=baseLightBlackColor;
    faxed3.textAlignment=NSTextAlignmentCenter;
    [self.view addSubview:faxed3];
    
    if(iPhoneX){
        
        [faxed3 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(120);
            make.height.mas_equalTo(14);
            make.bottom.equalTo(self.view.mas_bottom).with.offset(-18-34);
            make.leading.equalTo(faxed2.mas_trailing).with.offset(5);
        }];
        
    }else{
        
        [faxed3 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(120);
            make.height.mas_equalTo(14);
            make.bottom.equalTo(self.view.mas_bottom).with.offset(-18);
            make.leading.equalTo(faxed2.mas_trailing).with.offset(5);
        }];
        
    }
    
    UIButton* sureBut=[UIButton new];
    [sureBut setTitle:@"确定" forState:UIControlStateNormal];
    sureBut.backgroundColor=DEF_COLOR_MAINCOLOR;
    [sureBut setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [sureBut addTarget:self action:@selector(sureButClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:sureBut];
    [sureBut mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(80);
        make.height.mas_equalTo(52);
        make.bottom.equalTo(self.view.mas_bottom).with.offset(0);
        make.trailing.equalTo(self.view.mas_trailing).with.offset(0);
    }];
    
    if(iPhoneX){
        
        [sureBut mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(80);
            make.height.mas_equalTo(52);
            make.bottom.equalTo(self.view.mas_bottom).with.offset(0-34);
            make.trailing.equalTo(self.view.mas_trailing).with.offset(0);
        }];
        
    }else{
        
        [sureBut mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(80);
            make.height.mas_equalTo(52);
            make.bottom.equalTo(self.view.mas_bottom).with.offset(0);
            make.trailing.equalTo(self.view.mas_trailing).with.offset(0);
        }];
        
    }
    
}


// 清空
-(void)clearButClick{
    
    [self.Source_Dict removeAllObjects];
    [self.CollectionView reloadData];
    
}

// 创建数据
-(void)CreateSource{
    
    _Source_Array = [NSMutableArray arrayWithCapacity:Count_row];
    for (int i = 0; i < Count_row; i ++) {
        
        if ([Newtitle isEqualToString:@"七 乐 彩"]||[Newtitle isEqualToString:@"安徽 11选5"]) {
            [_Source_Array addObject:[NSString stringWithFormat:@"%d",i+1]];
        }else if ([Newtitle isEqualToString:@"3D 福 彩"]||[Newtitle isEqualToString:@"排 列 三"]||[Newtitle isEqualToString:@"排 列 五"]||[Newtitle isEqualToString:@"重庆时时彩"]||[Newtitle isEqualToString:@"3D 试验机"]){
            
            [_Source_Array addObject:[NSString stringWithFormat:@"%d",i]];
            
        }else{
            
            [_Source_Array addObject:[NSString stringWithFormat:@"%02d",i]];
            
        }
        
    }
    
}

// 摇一摇
-(void)shackButClick{
    //每次随机  清空Key数组
    [self.Key_Array removeAllObjects];
    [dataArray removeAllObjects];
    
    // 几个区 就循环几次
    for (int i = 0; i < Count_section; i ++ ) {
        [self.Key_Array addObject:[NSString stringWithFormat:@"%d",i]];
        // 随机出每个区的随机数
        NSMutableArray  *array_0 = [_Source_Array mutableCopy];
        NSMutableArray *arr = [NSMutableArray array];
        for (int j = 0; j < Count_Random; j ++ ) {
            
            if ([Newtitle isEqualToString:@"七 星 彩"]||[Newtitle isEqualToString:@"安徽 11选5"]) {
                index = arc4random()%array_0.count;
                
            }else if ([Newtitle isEqualToString:@"3D 福 彩"]||[Newtitle isEqualToString:@"排 列 三"]||[Newtitle isEqualToString:@"排 列 五"]||[Newtitle isEqualToString:@"重庆时时彩"]||[Newtitle isEqualToString:@"3D 试验机"]){
                
                index= arc4random()%array_0.count;
                
            }else{
                
                index = arc4random()%array_0.count;
                
            }
            
            //            NSLog(@"每个区的随机数下标 = %d",index);
            
            int n = [array_0[index] intValue];
            
            // 根据下标找到 数组中对应的元素  添加
            [arr addObject:[NSString stringWithFormat:@"%d",n]];
            [array_0 removeObjectAtIndex:index];
            // 按区 将数组加入字典中
            [self.Source_Dict setObject:arr forKey:[NSString stringWithFormat:@"%d",i]];
            //            NSLog(@"----%@",arr);
            
            NSString* str2=[arr componentsJoinedByString:@","];
            //            NSLog(@"%@",str2);
            
            if (Count_section==1) {
                
                dataArray=arr;
                //                NSLog(@"dataArray:%@",dataArray);
            }else{
                
                [dataArray addObject:str2];
                //                NSLog(@"dataArray:%@",dataArray);
            }
            
        }
        
    }
    //       NSLog(@"Key = %@",_Key_Array);
    NSLog(@"字典 = %@",_Source_Dict);
    
    
    [_CollectionView reloadData];
    
}

-(void)sureButClick{
    
    if (UserInfoShare.isLogin==YES) {
        
        if ([Newtitle isEqual:@"七 星 彩"]) {
            
            if (dataArray.count!=7) {
                
                [MXUtility showTips:@"必须选择7个球"];
                
            }else{
                
                BuyLotteryViewController* vc=[[BuyLotteryViewController alloc]init];
                vc.numArray=dataArray;
                vc.titleStr=Newtitle;
                vc.wanfaStr=Methods_Name;
                vc.lotteryType=parameters;
                [self.navigationController pushViewController:vc animated:YES];
            }
            
            
        }else if ([Newtitle isEqual:@"3D 福 彩"]){
            
            if (dataArray.count!=3) {
                
                [MXUtility showTips:@"必须选择3个球"];
                
            }else{
                
                BuyLotteryViewController* vc=[[BuyLotteryViewController alloc]init];
                vc.numArray=dataArray;
                vc.titleStr=Newtitle;
                vc.wanfaStr=Methods_Name;
                vc.lotteryType=parameters;
                [self.navigationController pushViewController:vc animated:YES];
            }
            
            
        }else if ([Newtitle isEqual:@"3D 试验机"]){
            
            if (dataArray.count!=3) {
                
                [MXUtility showTips:@"必须选择3个球"];
                
            }else{
                
                BuyLotteryViewController* vc=[[BuyLotteryViewController alloc]init];
                vc.numArray=dataArray;
                vc.titleStr=Newtitle;
                vc.wanfaStr=Methods_Name;
                vc.lotteryType=parameters;
                [self.navigationController pushViewController:vc animated:YES];
            }
            
            
        }else if ([Newtitle isEqual:@"排 列 三"]){
            
            if (dataArray.count!=3) {
                
                [MXUtility showTips:@"必须选择3个球"];
                
            }else{
                
                BuyLotteryViewController* vc=[[BuyLotteryViewController alloc]init];
                vc.numArray=dataArray;
                vc.titleStr=Newtitle;
                vc.wanfaStr=Methods_Name;
                vc.lotteryType=parameters;
                [self.navigationController pushViewController:vc animated:YES];
            }
            
            
        }else if ([Newtitle isEqual:@"排 列 五"]){
            
            if (dataArray.count!=5) {
                
                [MXUtility showTips:@"必须选择5个球"];
                
            }else{
                
                BuyLotteryViewController* vc=[[BuyLotteryViewController alloc]init];
                vc.numArray=dataArray;
                vc.titleStr=Newtitle;
                vc.wanfaStr=Methods_Name;
                vc.lotteryType=parameters;
                [self.navigationController pushViewController:vc animated:YES];
            }
            
            
        }else if ([Newtitle isEqual:@"重庆时时彩"]){
            
            if (dataArray.count!=5) {
                
                [MXUtility showTips:@"必须选择5个球"];
                
            }else{
                
                BuyLotteryViewController* vc=[[BuyLotteryViewController alloc]init];
                vc.numArray=dataArray;
                vc.titleStr=Newtitle;
                vc.wanfaStr=Methods_Name;
                vc.lotteryType=parameters;
                [self.navigationController pushViewController:vc animated:YES];
            }
            
            
        }else if ([Newtitle isEqual:@"安徽 11选5"]){
            
            if (dataArray.count!=5) {
                
                [MXUtility showTips:@"必须选择5个球"];
                
            }else{
                
                BuyLotteryViewController* vc=[[BuyLotteryViewController alloc]init];
                vc.numArray=dataArray;
                vc.titleStr=Newtitle;
                vc.wanfaStr=Methods_Name;
                vc.lotteryType=parameters;
                [self.navigationController pushViewController:vc animated:YES];
            }
            
        }else{
            
            BuyLotteryViewController* vc=[[BuyLotteryViewController alloc]init];
            vc.numArray=dataArray;
            vc.titleStr=Newtitle;
            vc.wanfaStr=Methods_Name;
            vc.lotteryType=parameters;
            [self.navigationController pushViewController:vc animated:YES];
            
        }
        
        
    }else{
        
        [MXUtility showTips:@"请先前去登录"];
        
    }
    
}

#pragma mark 返回多少个item
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
    return _Source_Array.count;
    
}

// 返回的区数
-(NSInteger )numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return Count_section;
}

#pragma mark 返回item
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"coll_cell" forIndexPath:indexPath];
    cell.NubleLab.text = _Source_Array[indexPath.row];
    cell.NubleLab.backgroundColor = [UIColor whiteColor];
    cell.NubleLab.textColor = [UIColor blackColor];
    
    NSString *key = _Key_Array[indexPath.section];
    NSArray *array = _Source_Dict[key];
    NSString *str;
    
    if ([Newtitle isEqualToString:@"七 乐 彩"]||[Newtitle isEqualToString:@"安徽 11选5"]) {
        str= [NSString stringWithFormat:@"%lu",indexPath.row+1];
        
    }else if ([Newtitle isEqualToString:@"3D 福 彩"]||[Newtitle isEqualToString:@"排 列 三"]||[Newtitle isEqualToString:@"排 列 五"]||[Newtitle isEqualToString:@"重庆时时彩"]||[Newtitle isEqualToString:@"3D 试验机"]){
        
        
        str= [NSString stringWithFormat:@"%lu",indexPath.row];
        
    }else{
        
        str= [NSString stringWithFormat:@"%lu",indexPath.row];
        
    }
    
    
    
    if ([array containsObject:str]) {
        cell.NubleLab.backgroundColor = [UIColor redColor];
        cell.NubleLab.textColor = [UIColor whiteColor];
        
    }else{
        cell.NubleLab.backgroundColor = [UIColor whiteColor];
        cell.NubleLab.textColor = [UIColor blackColor];
    }
    
    return cell;
    
}

//选择了某个cell
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    [MXUtility showTips:@"摇一摇,随机1注选号"];
    //    UICollectionViewCell *cell = [self.CollectionView cellForItemAtIndexPath:indexPath];
    //    CollectionViewCell *item = (CollectionViewCell *)cell;
    //
    //    if ([item.NubleLab.backgroundColor isEqual:[UIColor redColor]]) {  // 已选中
    //        item.NubleLab.backgroundColor = [UIColor whiteColor];
    //        item.NubleLab.textColor = [UIColor blackColor];
    //
    //    }else{
    //
    //        item.NubleLab.backgroundColor = [UIColor redColor];
    //        item.NubleLab.textColor = [UIColor whiteColor];
    //    }
    
}

//取消选择了某个cell
- (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath
{
    [MXUtility showTips:@"摇一摇,随机1注选号"];
    
    
}
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
    
    UICollectionReusableView *reusableView = nil;
    
    if (kind ==UICollectionElementKindSectionHeader) {
        
        MyHeaderView *headerV = (MyHeaderView *)[collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeaderView" forIndexPath:indexPath];
        
        headerV.textlabel2.text = section_array[indexPath.section];
        reusableView = headerV;
        
    }
    
    
    return reusableView;
    
}
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
    CGSize size={ScreenWidth,30 * Heigt_P};
    //    if (section == 0) {
    //        CGSize size={0,0};
    //        return size;
    //    }
    return size;
}

//定义每个UICollectionView 的大小
- ( CGSize )collectionView:( UICollectionView *)collectionView layout:( UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:( NSIndexPath *)indexPath

{
    
    return CGSizeMake (Width_P * 45  , Heigt_P * 45);
    
}

//定义每个Section 的 margin
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(5 * Heigt_P, 15 * Heigt_P, 5 * Heigt_P+5, 15 * Heigt_P);//分别为上、左、下、右
}

-(NSMutableDictionary *)Source_Dict{
    
    if (!_Source_Dict) {
        _Source_Dict = [NSMutableDictionary dictionary];
    }
    return _Source_Dict;
}



-(NSMutableArray *)Key_Array{
    
    if (!_Key_Array) {
        _Key_Array = [NSMutableArray array];
    }
    return _Key_Array;
    
}


- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event {
    NSLog(@"开始摇动");
    
    return;
}

- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event {
    NSLog(@"取消摇动");
    return;
}

- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
    if (event.subtype == UIEventSubtypeMotionShake) {
        NSLog(@"摇动结束");
        [self shackButClick];
        [self shakeshake];
        
    }
    return;
}

- (void)shakeshake {
    AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
}

-(NSMutableArray *)Other_Array{
    if (!_Other_Array) {
        _Other_Array = [NSMutableArray array];
    }
    return _Other_Array;
    
    // 模拟选号  查询  分析
    
}

@end
